package com.tao.controller;


import com.alibaba.fastjson.JSONObject;
import com.tao.pojo.*;
import com.tao.service.brand.IbrandService;
import com.tao.service.color.IcolorService;
import com.tao.service.product.IproductService;
import com.tao.service.storage.IstorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/product")
public class ProductController {
    @Autowired
    IbrandService brandService;
    @Autowired
    IcolorService colorService;
    @Autowired
    IstorageService storageService;
    @Autowired
    IproductService productService;

    @RequestMapping(value = "/getData.do",produces = "application/json;charset=utf-8")
    public String getData(){
        Map<String, List<?>> map=new HashMap<>();
		/* 查询所有的品牌对象*/
        Brand brand=new Brand();
        brand.setWithPage(0);
        BrandExample brandExample = new BrandExample();
        brandExample.createCriteria().andIsDelEqualTo(0);
        map.put("brands", brandService.query(brand,brandExample)) ;
		 /* 查询所有的颜色*/
        ColorExample colorExample=new ColorExample();
        colorExample.createCriteria().andIsDelEqualTo(0);
        map.put("colors", colorService.getColors(colorExample)) ;
		 /*查询所有的内存*/
        StorageExample storageExample=new StorageExample();
        storageExample.createCriteria().andIsDelEqualTo(0);
        map.put("storages", storageService.getStorage(storageExample)) ;
        return JSONObject.toJSONString(map);
    }

    @RequestMapping(value = "/getProduct.do",produces = "application/json;charset=utf-8")
    public String getProduct(ProductQuery productQuery){
        return JSONObject.toJSONString(productService.search(productQuery));
    }
}
